//
//  07_02.c
//  tasks
//
//  Created by Daniel on 2024/7/2.
//

#include <stdio.h>
#include <ctype.h>

void replaceSpace(char* str, int length)
{
    char* cur = str;
    int space_count = 0;
    while (*cur)
    {
        if(*str == ' ')
        {
            space_count++;
        }
        cur++;
    }
    int end1 = length - 1;
    int end2 = length + space_count * 2 - 1;
    while (end1 != end2) {
        if(str[end1] != ' ')
        {
            str[end2--] = str[end1--];
        }
        else
        {
            end1--;
            str[end2--] = '0';
            str[end2--] = '2';
            str[end2--] = '%';
        }
    }
}

int main()
{
    char a[] ="hello world";
    replaceSpace(a,11);
    printf("%s\n",a);
    return 0;
}

//没成功⬆️
